package moonstruckdrops.serviceImpl;

import javax.servlet.http.HttpServletRequest;

import moonstruckdrops.service.GoogleAccountService;

import org.apache.wicket.markup.html.link.ExternalLink;

import com.google.appengine.api.users.UserServiceFactory;

public class GoogleAccoutServiceImpl implements GoogleAccountService{
	
	public void init(HttpServletRequest request){
		Auth.setUserService(UserServiceFactory.getUserService());
		Auth.setRequestURL(request.getRequestURI());
		Auth.setPrincipal(request.getUserPrincipal());
	}
	
	public boolean AuthCheck(){
		if(Auth.getPrincipal() != null&&Auth.getUserService().isUserAdmin()){
			return true;	
		}else{
			return false;
		}
	}
	
	public ExternalLink AccoutURL(String WicketID){
		ExternalLink link = new ExternalLink(WicketID,Auth.getURL());
		return link;
	}
	
	public void CreateLoginURL(){
		Auth.setURL(Auth.getUserService().createLoginURL(Auth.getRequestURL()));
	}
	
	public void CreateLogoutURL(){
		Auth.setURL(Auth.getUserService().createLogoutURL(Auth.getRequestURL()));
	}
}